import React, { Component } from 'react'

class Main extends Component {

  // 此处的数据的它只执行1次
  state = {
    currentIndex: 0,
  }

  // 修改当前的左侧点击菜单
  setCurrentIndex = (currentIndex, currentKey) => {
    this.setState({
      currentIndex
    }, () => {
      this.props.setMainData(currentKey)
    })
  }

  // 执行N次
  render() {
    let { currentIndex } = this.state
    let { data, menu, mainData, navTabCurrentIndex } = this.props

    return (
      <div className='category-main-container'>
        <div className='slider'>
          <ul>
            {
              menu.map((item, index) => (
                <li onClick={() => this.setCurrentIndex(index, item)} key={index} class={currentIndex === index ? 'active' : ''}>
                  <span>{item}</span>
                </li>
              ))
            }
          </ul>
        </div>
        <div className='main'>
          <ul>
            {
              mainData && mainData.map((item, index) => (
                <li key={index}>
                  {item}
                </li>
              ))
            }
          </ul>
        </div>
      </div>
    )
  }
}

export default Main
